/***********************************************************************
	filename: 	CEGUIAnimate.cpp
	created:	13/3/2004
	author:		Paul D Turner
	
	purpose:	Implementation of Animate class members
*************************************************************************/
/***************************************************************************
 *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
 *
 *   Permission is hereby granted, free of charge, to any person obtaining
 *   a copy of this software and associated documentation files (the
 *   "Software"), to deal in the Software without restriction, including
 *   without limitation the rights to use, copy, modify, merge, publish,
 *   distribute, sublicense, and/or sell copies of the Software, and to
 *   permit persons to whom the Software is furnished to do so, subject to
 *   the following conditions:
 *
 *   The above copyright notice and this permission notice shall be
 *   included in all copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *   OTHER DEALINGS IN THE SOFTWARE.
 ***************************************************************************/
#include "CEGUIAnimate.h"
#include "CEGUIExceptions.h"
#include "CEGUITexture.h"
#include "CEGUIAnimateset.h"
#include "CEGUIRenderer.h"
#include "CEGUIPropertyHelper.h"
#include <cmath>
#include <iostream>

#include "CEGUIMask.h"

// Start of CEGUI namespace section
namespace CEGUI
{

/*************************************************************************
	Constructor
*************************************************************************/
Animate::Animate(const Animateset* owner, const String& name, bool bLoop, float fDelay) :
	d_owner(owner),
	d_bLoop(bLoop),
	d_fDelay(fDelay),
	d_name(name)
{
	if (!d_owner)
	{
		throw NullObjectException("Animate::Animate - Animateset pointer passed to Animate constructor must be valid.");
	}

}

/*************************************************************************
	Copy constructor
*************************************************************************/
Animate::Animate(const Animate& image) :
	d_owner(image.d_owner),
	d_name(image.d_name)
{

}

/*************************************************************************
	destructor
*************************************************************************/
Animate::~Animate(void)
{	
	
}

/*************************************************************************
	Clip and then queue the image to be rendered.
*************************************************************************/
void Animate::draw(const Rect& dest_rect, float z, const Rect& clip_rect, const ColourRect& colours, QuadSplitMode quad_split_mode,const Mask* mask) const
{
	// FIXME: animate d_owner->draw(d_currentImage->getSourceTextureArea(), dest_rect, z, clip_rect, colours, quad_split_mode, mask );

}

/*************************************************************************
	String object containing the name of this Animate	
*************************************************************************/
const String& Animate::getName(void) const
{
	return d_name;
}


/*************************************************************************
	Return the name of the Animateset that contains this Animate	
*************************************************************************/
const String& Animate::getAnimatesetName(void) const
{
	return d_owner->getName();
}

/*************************************************************************
    Output XML <Animate ... > element for this image
*************************************************************************/
void Animate::writeXMLToStream(XMLSerializer& xml_stream) const
{
    xml_stream.openTag("Animate")
        .attribute("Name", d_name)
        .attribute("Loop", PropertyHelper::boolToString(static_cast<uint>(d_bLoop)));

    xml_stream.closeTag();
}

void Animate::addImage(const String &name)
{
	// FIXME: animate
}

} // End of  CEGUI namespace section
